home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / graphics / vlapak1.zip / DMA_VLA.ZIP / DMA_VLA.TXT next >
Text File  |  1993-08-27  |  14KB  |  506 lines

  1. ─────────────────────────────────────────────────────────────────────────────
  2.                        INTRO TO DMA by Draeden of VLA
  3. ─────────────────────────────────────────────────────────────────────────────
  4.     
  5.  
  6.     DMA means Direct Memory Access.  You probably already know where and
  7. why you use it, so I'll skip right down to the dirty stuff.  This all 
  8. should speak for it's self, so... Enjoy.
  9.  
  10.     Draeden /VLA
  11.  
  12. ─────────────────────────────────────────────────────────────────────────────
  13.  
  14.     To do a DMA transfer, you need to know a few things:
  15.  
  16.         1)  Address of the memory to access
  17.  
  18.         2)  Length of data to read/write
  19.  
  20.     This can all be put into a structure:
  21.     
  22. STRUC DMAInfo
  23.     Page        db  ?
  24.     Offset      dw  ?
  25.     Length      dw  ?
  26. ENDS
  27.  
  28.     Page is the highest 4 bits of the absolute 20 bit address of the memory
  29. location.  Note that DMA transfers CANNOT cross 64k page boundries.
  30.     
  31.     The Length is actually LENGTH-1; sending in a 0 will move 1 byte,
  32. sending a 0FFFFh will move 64k.
  33.  
  34.     ─────────────────────────────────────────────────────────────────────
  35.     ; IN: DX:AX = segment/offset address of memory area
  36.     ;
  37.     ;OUT: DH = Page (0-F)  (DL is destroyed)
  38.     ;     AX = Offset
  39.     ─────────────────────────────────────────────────────────────────────
  40. PROC MakePage
  41.     push    bx
  42.  
  43.     mov     bl,dh
  44.     shr     bl,4    ;isolate upper 4 bits of segment
  45.  
  46.     shl     dx,4    ;make segment into ABS address
  47.     add     ax,dx   ;add the offset and put it in AX
  48.     adc     bl,0    ;complete the addition
  49.  
  50.     mov     dh,bl   ;put the PAGE where it goes
  51.  
  52.     pop     bx      ; DH:AX is now the PAGE:OFFSET address
  53.     ret
  54. ENDP
  55.  
  56. ─────────────────────────────────────────────────────────────────────────────
  57.     Programming DMA channels 0 thru 3
  58. ─────────────────────────────────────────────────────────────────────────────
  59.     There are 3 ports that are DMA channel specific:
  60.  
  61.         1) The Page register
  62.         2) The DMA count (length) register
  63.         3) The memory address (offset register)
  64.  
  65.     They are as follows:
  66.  
  67. DMACH   PAGE    ADDRESS  LENGTH
  68.  
  69.  0       87h       0       1
  70.  
  71.  1       83h       2       3
  72.  
  73.  2       81h       4       5
  74.  
  75.  3       82h       6       7
  76.  
  77.         
  78.     And now some general registers:
  79.  
  80.  DMA Mask Register:  0Ah
  81. ────────────────────────
  82.         bit 7 - 3 = 0  Reserved
  83.  
  84.             bit 2 = 0  clear mask
  85.                   = 1  set mask
  86.  
  87.        bits 1 - 0 = 00 Select channel 0
  88.                   = 01 select channel 1
  89.                   = 10 select channel 2
  90.                   = 11 select channel 3
  91.  
  92.        USE: You must set the mask of the channel before you
  93.             can reprogram it.
  94.  
  95.  DMA Mode Register:  0Bh
  96. ────────────────────────
  97.         bit 7 - 6 = 00 Demand mode
  98.                   = 01 Signal mode
  99.                   = 10 Block mode
  100.                   = 11 Cascade mode
  101.  
  102.         bit 5 - 4 = 0  Reserved
  103.  
  104.         bit 3 - 2 = 00 Verify operation
  105.                   = 01 Write operation
  106.                   = 10 Read operation
  107.                   = 11 Reserved
  108.  
  109.        bits 1 - 0 = 00 Select channel 0
  110.                   = 01 select channel 1
  111.                   = 10 select channel 2
  112.                   = 11 select channel 3
  113.  
  114.        USE: Tell the DMAC what to do. Common modes are:
  115.  
  116.             48h (Read operation, Signal mode)
  117.                 Used to read data from host memory and send to whomever
  118.                 polls it.
  119.  
  120.             44h (Write operation, Signal mode)
  121.                 Used to write data taken from a device to memory.
  122.  
  123. DMA clear byte ptr:  0Ch
  124. ────────────────────────
  125.        USE: Send a zero to reset the internal ptrs
  126.  
  127.  
  128.  
  129.     WHAT TO DO:
  130. ────────────────────────
  131.  
  132.     1) Set the Mask bit for the channel
  133.  
  134.         mov     al,4
  135.         add     al,[DMA_Channel]
  136.         out     0ah,al
  137.  
  138.     2) Clear Byte Ptr
  139.  
  140.         sub     al,al
  141.         out     0Ch,al
  142.  
  143.     3) Set the DMA transfer mode
  144.  
  145.         mov     al,48h                  ;MODE output (read)
  146.         add     al,[DMA_Channel]
  147.         out     0Bh,al
  148.  
  149.     4) Set the memory ADDRESS and LENGTH
  150.  
  151.         ;        AX = offset
  152.         ;        CX = Length
  153.         ;[DMA_Base] = port # of memory address
  154.         
  155.         mov     dx,[DMA_Base]
  156.         out     dx,al                   ;send lower byte address
  157.         mov     al,ah
  158.         out     dx,al                   ;send high byte address
  159.  
  160.         inc     dl                  ;point to Count port
  161.         mov     al,cl
  162.         out     dx,al                   ;send low byte length
  163.         mov     al,ch
  164.         out     dx,al                   ;send high byte length
  165.  
  166.     5) Set the DMA page
  167.  
  168.         ; AL = Page
  169.  
  170.         mov     dx,[Dma_Page]
  171.         out     dx,al                   ; write the Page
  172.  
  173.     6) Clear DMA mask bit
  174.  
  175.         mov     al,[byte DMA_Channel]
  176.         out     0Ah,al                  ; port 0Ah, DMA-1 mask reg bit
  177.  
  178.     7) Program the other device that is going to use the DMA output/input
  179.  
  180.  
  181.     ─────────────────────────────────────────────────────────────────────
  182.     ; This routine programs the DMAC for channels 0-3
  183.     ;
  184.     ; IN: [DMA_Channel], [DMAbaseAdd], [DMApageReg] must be setup
  185.     ;       [DAMBaseAdd] =  Memory Address port
  186.     ;
  187.     ;     dh = mode
  188.     ;     ax = address
  189.     ;     cx = length  
  190.     ;     dl = page
  191.     ─────────────────────────────────────────────────────────────────────
  192. PROC Prog_DMA03 NEAR
  193.         push    bx
  194.         mov     bx,ax
  195.  
  196.         mov     al,4
  197.         add     al,[DMA_Channel]
  198.         out     0Ah,al          ; mask reg bit
  199.  
  200.         sub     al,al
  201.         out     0Ch,al          ; clr byte ptr
  202.  
  203.         mov     al,dh
  204.         add     al,[DMA_Channel]
  205.         out     0Bh,al          ; set mode reg
  206.  
  207.         push    dx
  208.         
  209.         mov     dx,[DMAbaseAdd]
  210.         mov     al,bl
  211.         out     dx,al           ; set base address low
  212.         mov     al,bh
  213.         out     dx,al           ; set base address high
  214.  
  215.         inc     dx              ;point to length
  216.         mov     al,cl
  217.         out     dx,al           ; set length low
  218.         mov     al,ch
  219.         out     dx,al           ; set length high
  220.  
  221.         pop     dx
  222.  
  223.         mov     al,dl
  224.         mov     dx,[DmaPageReg]
  225.         out     dx,al           ; set DMA page reg
  226.  
  227.         mov     al,[DMA_Channel]
  228.         out     0Ah,al          ; unmask (activate) dma channel
  229.         pop     bx
  230.         ret
  231. ENDP
  232.  
  233. ─────────────────────────────────────────────────────────────────────────────
  234. ─────────────────────────────────────────────────────────────────────────────
  235.     Programming DMA channels 4 thru 7
  236. ─────────────────────────────────────────────────────────────────────────────
  237. ─────────────────────────────────────────────────────────────────────────────
  238.  
  239.     Again, there are 3 ports that are DMA channel specific:
  240.  
  241.         1) The Page register
  242.         2) The DMA count (length) register
  243.         3) The memory address (offset register
  244.  
  245.     They are as follows:
  246.  
  247. DMACH   PAGE    ADDRESS  LENGTH
  248.  
  249.  4       8Fh      C0h      C2h  
  250.  
  251.  5       8Bh      C4h      C6h  
  252.  
  253.  6       89h      C8h      CAh  
  254.  
  255.  7       8Ah      CCh      CEh 
  256.  
  257.  
  258.     And now some general registers:
  259.  
  260.  DMA Mask Register: 0D4h
  261. ────────────────────────
  262.         bit 7 - 3 = 0  Reserved
  263.  
  264.             bit 2 = 0  clear mask
  265.                   = 1  set mask
  266.  
  267.        bits 1 - 0 = 00 Select channel 4
  268.                   = 01 select channel 5
  269.                   = 10 select channel 6
  270.                   = 11 select channel 7
  271.  
  272.        USE: You must set the mask of the channel before you
  273.             can reprogram it.
  274.  
  275.  DMA Mode Register: 0D6h
  276. ────────────────────────
  277.         bit 7 - 6 = 00 Demand mode
  278.                   = 01 Signal mode
  279.                   = 10 Block mode
  280.                   = 11 Cascade mode
  281.  
  282.         bit 5 - 4 = 0  Reserved
  283.  
  284.         bit 3 - 2 = 00 Verify operation
  285.                   = 01 Write operation
  286.                   = 10 Read operation
  287.                   = 11 Reserved
  288.  
  289.        bits 1 - 0 = 00 Select channel 4
  290.                   = 01 select channel 5
  291.                   = 10 select channel 6
  292.                   = 11 select channel 7
  293.  
  294.        USE: Tell the DMAC what to do. Common modes are:
  295.  
  296.             48h (Read operation, Signal mode)
  297.                 Used to read data from host memory and send to whomever
  298.                 polls it.
  299.  
  300.             44h (Write operation, Signal mode)
  301.                 Used to write data taken from a device to memory.
  302.  
  303. DMA clear byte ptr: 0D8h
  304. ────────────────────────
  305.        USE: Send a zero to reset the internal ptrs
  306.  
  307.  
  308.     WHAT TO DO: (exactly the same thing, just different io PORTs)
  309. ────────────────────────
  310.  
  311.     1) Set the Mask bit for the channel
  312.  
  313.         mov     al,[DMA_Channel]    ;because the DMA's are 4-7, bit #3
  314.         out     0D4h,al             ; is already set
  315.  
  316.     2) Clear Byte Ptr
  317.  
  318.         sub     al,al
  319.         out     0D8h,al
  320.  
  321.     3) Set the DMA transfer mode
  322.         
  323.         mov     al,[DMA_Channel]
  324.         sub     al,4
  325.         or      al,48h                  ;MODE output (read)
  326.         out     0D6h,al
  327.  
  328.     4) Set the memory ADDRESS and LENGTH
  329.  
  330.         ;        AX = offset
  331.         ;        CX = Length
  332.         ;[DMA_Base] = port # of memory address
  333.         
  334.         mov     dx,[DMA_Base]
  335.         out     dx,al                   ;send lower byte address
  336.         mov     al,ah
  337.         out     dx,al                   ;send high byte address
  338.  
  339.         add     dl,2                ;point to Count port (seperated by 2)
  340.         mov     al,cl
  341.         out     dx,al                   ;send low byte length
  342.         mov     al,ch
  343.         out     dx,al                   ;send high byte length
  344.  
  345.     5) Set the DMA page
  346.  
  347.         ; AL = Page
  348.  
  349.         mov     dx,[Dma_Page]
  350.         out     dx,al                   ; write the Page
  351.  
  352.     6) Clear DMA mask bit
  353.  
  354.         mov     al,[byte DMA_Channel]
  355.         and     al,00000011b
  356.         out     0d4h,al                 ; port 0Ah, DMA-1 mask reg bit
  357.  
  358.     7) Program the other device that is going to use the DMA output/input
  359.  
  360.  
  361.     ─────────────────────────────────────────────────────────────────────
  362.     ; This routine programs the DMAC for channels 4-7
  363.     ;
  364.     ; IN: [DMA_Channel], [DMAbaseAdd], [DMApageReg] must be setup
  365.     ;       [DAMBaseAdd] =  Memory Address port
  366.     ;
  367.     ;     dh = mode
  368.     ;     ax = address
  369.     ;     cx = length  
  370.     ;     dl = page
  371.     ─────────────────────────────────────────────────────────────────────
  372. PROC Prog_DMA47 NEAR
  373.         push    bx
  374.         mov     bx,ax
  375.  
  376.         mov     al,[DMA_Channel]
  377.         out     0D4h,al         ; mask reg bit
  378.  
  379.         sub     al,al
  380.         out     0D8h,al         ; clr byte ptr
  381.  
  382.         mov     al,[DMA_Channel]
  383.         sub     al,4
  384.         add     al,dh
  385.         out     0D6h,al         ; set mode reg
  386.  
  387.         push    dx
  388.  
  389.         mov     dx,[DMAbaseAdd]
  390.         mov     al,bl
  391.         out     dx,al           ; set base address low
  392.         mov     al,bh
  393.         out     dx,al           ; set base address high
  394.  
  395.         add     dl,2            ;point to length
  396.         mov     al,cl
  397.         out     dx,al           ; set length low
  398.         mov     al,ch
  399.         out     dx,al           ; set length high
  400.  
  401.         pop     dx
  402.  
  403.         mov     al,dl
  404.         mov     dx,[DmaPageReg]
  405.         out     dx,al           ; set DMA page reg
  406.  
  407.         mov     al,[DMA_Channel]
  408.         and     al,00000011b
  409.         out     0D4h,al         ; unmask (activate) dma channel
  410.         pop     bx
  411.         ret
  412. ENDP
  413.  
  414.     ─────────────────────────────────────────────────────────────────────
  415.     ; This routine programs the DMAC for channels 0-7
  416.     ;
  417.     ; IN: [DMA_Channel], [DMAbaseAdd], [DMApageReg] must be setup
  418.     ;       [DAMBaseAdd] =  Memory Address port
  419.     ;
  420.     ;     dh = mode
  421.     ;     ax = address
  422.     ;     cx = length  
  423.     ;     dl = page
  424.     ─────────────────────────────────────────────────────────────────────
  425. PROC Prog_DMA NEAR
  426.         push    bx
  427.         mov     bx,ax
  428.  
  429.         cmp     [DMA_Channel],4
  430.         jb      @@DoDMA03
  431.  
  432.         mov     al,[DMA_Channel]
  433.         out     0D4h,al         ; mask reg bit
  434.  
  435.         sub     al,al
  436.         out     0D8h,al         ; clr byte ptr
  437.  
  438.         mov     al,[DMA_Channel]
  439.         sub     al,4
  440.         add     al,dh
  441.         out     0D6h,al         ; set mode reg
  442.  
  443.         push    dx
  444.  
  445.         mov     dx,[DMAbaseAdd]
  446.         mov     al,bl
  447.         out     dx,al           ; set base address low
  448.         mov     al,bh
  449.         out     dx,al           ; set base address high
  450.  
  451.         add     dl,2            ;point to length
  452.         mov     al,cl
  453.         out     dx,al           ; set length low
  454.         mov     al,ch
  455.         out     dx,al           ; set length high
  456.  
  457.         pop     dx
  458.  
  459.         mov     al,dl
  460.         mov     dx,[DmaPageReg]
  461.         out     dx,al           ; set DMA page reg
  462.  
  463.         mov     al,[DMA_Channel]
  464.         and     al,00000011b
  465.         out     0D4h,al         ; unmask (activate) dma channel
  466.         pop     bx
  467.         ret
  468.  
  469. @@DoDMA03:
  470.         mov     al,4
  471.         add     al,[DMA_Channel]
  472.         out     0Ah,al          ; mask reg bit
  473.  
  474.         sub     al,al
  475.         out     0Ch,al          ; clr byte ptr
  476.  
  477.         mov     al,dh
  478.         add     al,[DMA_Channel]
  479.         out     0Bh,al          ; set mode reg
  480.  
  481.         push    dx
  482.         
  483.         mov     dx,[DMAbaseAdd]
  484.         mov     al,bl
  485.         out     dx,al           ; set base address low
  486.         mov     al,bh
  487.         out     dx,al           ; set base address high
  488.  
  489.         inc     dx              ;point to length
  490.         mov     al,cl
  491.         out     dx,al           ; set length low
  492.         mov     al,ch
  493.         out     dx,al           ; set length high
  494.  
  495.         pop     dx
  496.  
  497.         mov     al,dl
  498.         mov     dx,[DmaPageReg]
  499.         out     dx,al           ; set DMA page reg
  500.  
  501.         mov     al,[DMA_Channel]
  502.         out     0Ah,al          ; unmask (activate) dma channel
  503.         pop     bx
  504.         ret
  505. ENDP
  506.